package com.example.demo.Controller;

import com.common.vo.Result;
import com.example.demo.Mapper.UserMapper;
import com.example.demo.Service.UserService;
import com.example.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller

public class UserController {

    @Autowired
    private UserService userService;

    @Resource
    private UserMapper userMapper;




    @ResponseBody
    @PostMapping("/login1")
    public Result login(String username,String password, HttpSession session){//获取请求参数
        //利用Service层处理登录，若返回null则没找到对象
        User user = new User(null, username, password, null);
        User login = userService.login(user);
        if(login!=null){
                //防止密码泄露
                user.setPassword(null);
                //防止跳过登录
                session.setAttribute("login",user);
                return   Result.success();

        }
         return  Result.loginfalse();


    }
}
